package com.acme.bankapp.domain.bank;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.acme.bankapp.exceptions.bank.ClientExistsException;
import com.acme.bankapp.exceptions.bank.NotEnoughFundsException;
import com.acme.bankapp.exceptions.bank.OverDraftLimitExceededException;
import com.acme.bankapp.service.bank.BankService;

import static com.acme.bankapp.service.bank.BankService.addAccount;
import static com.acme.bankapp.service.bank.BankService.addClient;

public class BankApplication {
	
	public static void modifyBank(Bank bank, int idOfClient, String depositOrWithdraw, 
			int numOfAccount, int sum) throws NotEnoughFundsException, IllegalArgumentException{
		
		ArrayList<Client> clients = bank.getClients();
		if(!(depositOrWithdraw.equals("deposit") || depositOrWithdraw.equals("withdraw")) 
				|| clients.size() < idOfClient + 1){
			throw new IllegalArgumentException("IllegalArgumentException");
		}
		else if(clients.get(idOfClient).getAccounts().size() < numOfAccount + 1){
			throw new IllegalArgumentException("IllegalArgumentException");
		}
		else{
			if(depositOrWithdraw.equals("deposit")){
				clients.get(idOfClient).getAccounts().get(numOfAccount).deposit(sum);
			}
			else if(depositOrWithdraw.equals("withdraw"))
				clients.get(idOfClient).getAccounts().get(numOfAccount).withdraw(sum);
		}
	}
	
	public static void main(String[] args){
		SavingsAccount sa1 = new SavingsAccount(20);
		SavingsAccount sa2 = sa1;
		System.out.println(sa1 == sa2);
		System.out.println(sa1.equals(sa2));
		System.out.println("Hashcode sa1 --  " + sa1.hashCode() + 
				", Hashcode sa2 -- " + sa2.hashCode());
		
		CheckingAccount ca3 = new CheckingAccount(100, 20);
		SavingsAccount sa4 = new SavingsAccount(100);
		System.out.println(ca3.equals(sa4));
		System.out.println("Hashcode ca3 --  " + ca3.hashCode() + 
				", Hashcode ca3 -- " + sa4.hashCode());

		Client cl1 = new Client("Ivanov", Gender.MALE, 100,20);
		Client cl2 = new Client("Ivanov", Gender.FEMALE, 100,20);
		System.out.println(cl1.equals(cl2));
		System.out.println("Hashcode cl1 --  " + cl1.hashCode() + 
				", Hashcode cl2 -- " + cl2.hashCode());
				
		Bank b = new Bank();
		try{
		addClient(b, new Client("Ivanov", Gender.MALE, 1000,20));
		addClient(b, new Client("Petrova", Gender.FEMALE, 2000));
		addClient(b, new Client("Sidorov", Gender.MALE, 1500,200));
		addAccount(b, 0, 400);
		addAccount(b, 2, 4000, 300);
		System.out.println("\n");
		BankService.printBank(b);		
		}catch(ClientExistsException e){}
	}
}
